package cate.game.play.skill.passive.fairy;

import cate.common.table.d.GDSkill;
import cate.common.util.XT;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.skill.effect.SkillEffect;
import cate.game.play.skill.passive.PassiveHandler;

import java.util.List;

/**
 * 效果1：奇数回合免伤提高15%，偶数回合伊比利亚火腿的普通攻击技能系数为150%。
 * 效果2：“圣剑压制”追加概率增加10%，追加伤害增加10%，追击后随机溅射一名周围目标，伤害为追加伤害的20%
 */
public class 伊比利亚火腿灵器PH extends PassiveHandler {

	private int buff;

	private double 伤害系数;

	private String 溅射技能标签;

	private double 血量调整;

	private int 溅射人数;

	//buff=？？&伤害系数=5000&溅射技能标签=圣罚&血量调整=2000&溅射人数=1
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		buff = args.getInt("buff", 0);
		伤害系数 = args.getDouble("伤害系数", 0d);

		溅射技能标签 = args.get("溅射技能标签");
		血量调整 = args.getWDouble("血量调整", 0d);
		溅射人数 = args.getInt("溅射人数", 0);
	}

	@Override
	public void onRoundBegin(ActionCtx action) {
		if (action.getRound().isOddRound()) {
			skill.owner.buff.tryAddByTid(action, buff);
		}
	}

	@Override
	public void afterSelectTargets(SkillActionCtx action, SkillEffect effect) {
		handleAttack(action,effect);
		handleSplash(action,effect);
	}


	private void handleAttack(SkillActionCtx action, SkillEffect effect) {
		if (action.getRound().isOddRound()) {
			return;
		}
		if (!action.getSkill().cfg.isType(GDSkill.Type.ATTACK)) {
			return;
		}
		effect.addHpCfgByCoeff(伤害系数);
	}

	private void handleSplash(SkillActionCtx action, SkillEffect effect) {
		if (!action.getSkill().cfg.containTag(溅射技能标签)) {
			return;
		}
		List<Fighter> exTargets = TargetSelector.findRetargetTargets(action.getTeamVs(), GDSkill.Retarget.OTHER, action.getTargets());
		XT.randomPick(exTargets, 溅射人数, false);
		if (XT.isBlank(exTargets)) {
			return;
		}
		action.getTargets().addAll(exTargets);
		for (Fighter target : exTargets) {
			effect.getTargetCtx(target.getPid()).addHpChangeRate(血量调整);
		}
	}
}
